package cn.hcbycloud.auth.service;

import cn.hcbycloud.auth.bo.RolePermissionBO;
import cn.hcbycloud.auth.mapper.RolePermissionMapper;
import cn.hcbycloud.auth.model.RolePermission;
import cn.hcbycloud.common.core.exception.CustomizeException;
import cn.hcbycloud.common.core.utils.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色权限关系表
 *
 * @author gaoheng
 * @date 2022-01-23 21:43:36
 */
@Service
@AllArgsConstructor
public class RolePermissionService extends ServiceImpl<RolePermissionMapper, RolePermission> {
    private RolePermissionMapper rolePermissionMapper;

    /**
     * 建立角色权限关系
     * @param rolePermissionBoList
     */
    public void addRolePermissionInfo(List<RolePermissionBO> rolePermissionBoList) {
        try {
            List<RolePermission> rolePermissionList = ObjectUtils.cloneObjList(rolePermissionBoList, RolePermission.class);
            rolePermissionList.forEach(item -> {
                item.preInsert();
            });
            this.saveBatch(rolePermissionList);
        } catch (Exception e) {
            throw new CustomizeException("建立角色权限关系错误");
        }
    }
}
